﻿#region Copyright Notice
// 
// 
// Copyright (c) 2009-2010 Anindya Chatterjee
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 
// 
// 
#endregion
using System;
using System.ComponentModel;
using System.Serialization;

namespace GCore
{
    /// <summary>
    /// Provides data for the <see cref="GCore.GService&lt;TFeed,TEntry&gt;.SubmitNewEntryCompleted"/> event of <see cref="GService&lt;TFeed,TEntry&gt;"/>.
    /// </summary>
    /// <typeparam name="TFeed">Type of atom feed for the service.</typeparam>
    /// <typeparam name="TEntry">Type of atom feed entry for the service.</typeparam>
    public class SubmitNewEntryCompletedEventArgs<TFeed, TEntry> : AsyncCompletedEventArgs
        where TFeed : GFeed<TEntry>, new()
        where TEntry : GEntry, new()
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="GCore.SubmitNewEntryCompletedEventArgs&lt;TFeed,TEntry&gt;"/> class.
        /// </summary>
        /// <param name="result">The <see cref="TEntry"/> result.</param>
        /// <param name="error"> Any error that occurred during the asynchronous operation.</param>
        /// <param name="cancelled">A value indicating whether the asynchronous operation was canceled.</param>
        /// <param name="userState">A unique user state.</param>
        public SubmitNewEntryCompletedEventArgs(string result, Exception error, bool cancelled, object userState)
            : base(error, cancelled, userState)
        {
            var serializer = new XObjectSerializer<TEntry>();
            TEntry entry = serializer.Deserialize(result);
            Result = entry;
        }

        /// <summary>
        /// Gets the result of the asynchronous operation as an atom feed object.
        /// </summary>
        /// <value>An atom feed object.</value>
        public TEntry Result { get; private set; }
    }
}